package com.ruoyi.business.controller;

import java.security.Security;
import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.ip.IpUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.SystemLogs;
import com.ruoyi.business.service.ISystemLogsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 系统登录和参数日志Controller
 * 
 * @author DL
 * @date 2025-07-09
 */
@RestController
@RequestMapping("/logs")
public class SystemLogsController extends BaseController
{
    @Autowired
    private ISystemLogsService systemLogsService;

    /**
     * 查询系统登录和参数日志列表
     */
    //@RequiresPermissions("business:logs:list")
    @GetMapping("/list")
    public TableDataInfo list(SystemLogs systemLogs)
    {
        startPage();
        List<SystemLogs> list = systemLogsService.selectSystemLogsList(systemLogs);
        return getDataTable(list);
    }

    /**
     * 导出系统登录和参数日志列表
     */
    //@RequiresPermissions("business:logs:export")
    @Log(title = "系统登录和参数日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SystemLogs systemLogs)
    {
        List<SystemLogs> list = systemLogsService.selectSystemLogsList(systemLogs);
        ExcelUtil<SystemLogs> util = new ExcelUtil<SystemLogs>(SystemLogs.class);
        util.exportExcel(response, list, "系统登录和参数日志数据");
    }

    /**
     * 获取系统登录和参数日志详细信息
     */
    //@RequiresPermissions("business:logs:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(systemLogsService.selectSystemLogsById(id));
    }

    /**
     * 新增系统登录和参数日志
     */
    //@RequiresPermissions("business:logs:add")
    @Log(title = "系统登录和参数日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SystemLogs systemLogs)
    {
        systemLogs.setLoginName(SecurityUtils.getUsername());
        systemLogs.setCreatedAt(new Date());
        systemLogs.setLoginDevice(IpUtils.getIpAddr());
        return toAjax(systemLogsService.insertSystemLogs(systemLogs));
    }

    /**
     * 修改系统登录和参数日志
     */
    //@RequiresPermissions("business:logs:edit")
    @Log(title = "系统登录和参数日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SystemLogs systemLogs)
    {
        return toAjax(systemLogsService.updateSystemLogs(systemLogs));
    }

    /**
     * 删除系统登录和参数日志
     */
    //@RequiresPermissions("business:logs:remove")
    @Log(title = "系统登录和参数日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(systemLogsService.deleteSystemLogsByIds(ids));
    }
}
